package com.htudata.transctAlarm.dao;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import java.util.List;

import com.htudata.alarm.pojo.po.AlarmLevelPO;
import com.htudata.transctAlarm.mapper.TransctAlarmMapper;
import com.htudata.transctAlarm.zabbix.mapper.ZabbixTransctAlarmMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

@Repository
public class TransctAlarmDao {

  @Autowired
  private TransctAlarmMapper alarmMapper;
  
  @Autowired
  private ZabbixTransctAlarmMapper zabbixAlarmMapper;
  
  public List<AlarmLevelPO> selectAlarmLevelList(int normal_level) {
    JSONObject params = new JSONObject();
    params.put("normal_level", Integer.valueOf(normal_level));
    return this.alarmMapper.selectAlarmLevelList(params);
  }
  
  public JSONArray selectNodeProblemCountByFlowId(String flowId, int recoverTime) {
    JSONObject params = new JSONObject();
    params.put("flowId", flowId);
    return this.alarmMapper.selectNodeProblemCountByFlowId(params);
  }
  
  public JSONArray selectNodeAlarmCountByFlowId(String flowId, int recoverTime, long userId) {
    JSONObject params = new JSONObject();
    params.put("flowId", flowId);
    params.put("userId", Long.valueOf(userId));
    return this.alarmMapper.selectNodeAlarmCountByFlowId(params);
  }
  
  public JSONArray selectAlarmHistoryByTriggerId(long triggerId, long startTime, long endTime) {
    return this.alarmMapper.selectAlarmHistoryByTriggerId(triggerId, startTime, endTime);
  }
  
  public int updateAlarmStatusByAlarmId(long alarmId, int status, long recoverTime) {
    return this.alarmMapper.updateAlarmStatusByAlarmId(alarmId, status, recoverTime);
  }
  
  public JSONArray selectEffectiveLocalAlarms() {
    return this.alarmMapper.selectEffectiveLocalAlarms();
  }
  
  public JSONArray selectZabbixProblemsByTriggerId(long triggerId, long startTime, long endTime) {
    return this.zabbixAlarmMapper.selectZabbixProblemsByTriggerId(triggerId, startTime, endTime);
  }
  
  public JSONArray selectNodeProblemCountByVirtualStation(int recoverTime, int nodeTypeId, String nodeId, String areaCode) {
    JSONObject params = new JSONObject();
    params.put("nodeTypeId", Integer.valueOf(nodeTypeId));
    params.put("nodeId", nodeId);
    params.put("areaCode", areaCode);
    return this.alarmMapper.selectNodeProblemCountByVirtualStation(params);
  }
  
  public JSONArray selectNodeAlarmCountByVirtualStation(int recoverTime, int nodeTypeId, String nodeId, String areaCode) {
    JSONObject params = new JSONObject();
    params.put("nodeTypeId", Integer.valueOf(nodeTypeId));
    params.put("nodeId", nodeId);
    params.put("areaCode", areaCode);
    return this.alarmMapper.selectNodeAlarmCountByVirtualStation(params);
  }
  
  public JSONArray selectNodeProblemCountByLevel(int recoverTime, int nodeTypeId, String nodeId, String areaCode, int level) {
    JSONObject params = new JSONObject();
    params.put("nodeTypeId", Integer.valueOf(nodeTypeId));
    params.put("nodeId", nodeId);
    params.put("areaCode", areaCode);
    params.put("level", Integer.valueOf(level));
    return this.alarmMapper.selectNodeProblemCountByLevel(params);
  }
  
  public JSONArray selectNodeAlarmCountByLevel(int recoverTime, int nodeTypeId, String nodeId, String areaCode, int level) {
    JSONObject params = new JSONObject();
    params.put("nodeTypeId", Integer.valueOf(nodeTypeId));
    params.put("nodeId", nodeId);
    params.put("areaCode", areaCode);
    params.put("level", Integer.valueOf(level));
    return this.alarmMapper.selectNodeAlarmCountByLevel(params);
  }
  
  public int updateTriggerStatus(int isTriggered, long alarmId) {
    return this.alarmMapper.updateTriggerStatus(isTriggered, alarmId);
  }
}
